home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Linux Cubed Series 7: Sunsite
/
Linux Cubed Series 7 - Sunsite Vol 1.iso
/
system
/
emulator
/
bsvc-1.000
/
bsvc-1
/
bsvc-1.0.4
/
src
/
Assemblers
/
68kasm
/
include.c
< prev
next >
Wrap
C/C++ Source or Header
|
1995-07-26
|
2KB
|
73 lines
/******************************************************************************
* $Id: include.c,v 1.3 1995/01/13 00:38:29 bmott Exp $
******************************************************************************
*
* Handle INCLUDE directives in the source code
*
******************************************************************************
* $Log: include.c,v $
* Revision 1.3 1995/01/13 00:38:29 bmott
* Fixed a stupid problem!
*
* Revision 1.2 1995/01/01 05:37:23 bmott
* Fixed problem with INCLUDE having to be in uppercase
*
* Revision 1.1 1994/09/21 22:29:26 bmott
* Initial revision
*
*****************************************************************************/
#include <stdio.h>
#include <stdlib.h>
char* buildCompleteSourceFile(FILE* currentFile, char* currentFileName,
FILE* completeFile, int level)
{
FILE* includeFile;
char buffer[8192], directive[1024], operand[1024], *error;
/* Make sure we don't loop forever */
if(level>15)
return("Too many nested INCLUDEs\n");
while(1)
{
fgets(buffer,sizeof(buffer),currentFile);
if(feof(currentFile))
break;
if(sscanf(buffer,"%s %s", directive, operand) == 2)
{
if(strcasecmp(directive,"INCLUDE")==0)
{
includeFile=fopen(operand,"r");
if(!includeFile)
{
char* tmp = (char*)malloc(256);
sprintf(tmp,"Could not find INCLUDE file: %s\n for file: %s\n",
operand, currentFileName);
return(tmp);
}
error = buildCompleteSourceFile(includeFile, operand, completeFile,
level+1);
fclose(includeFile);
if(error)
return(error);
}
else
{
fprintf(completeFile,"%s", buffer);
}
}
else
{
fprintf(completeFile,"%s", buffer);
}
}
return(NULL);
}